{extend name="base" /}
{block name="title"}<title>登录界面</title>{/block}
{block name="style"}
<link rel="stylesheet" href="__CSS__/resets.css" />
<link rel="stylesheet" href="__CSS__/common.css" />
<link rel="stylesheet" href="__CSS__/font-awesome.min.css" />
{/block}
{block name="body"}
<div class="wrap login_wrap">
    <div class="content">
        <div class="logo"></div>
        <div class="login_box">

            <div class="login_form">
                <div class="login_title">
                    登录
                </div>
                <form id="loginForm" action="#" method="post">

                    <div class="form_text_ipt">
                        <input name="username" type="text" placeholder="用户名">
                    </div>
                    <div class="ececk_warning"><span>用户名不能为空</span></div>
                    <div class="form_text_ipt">
                        <input name="password" type="password" placeholder="密码">
                    </div>
                    <div class="ececk_warning"><span>密码不能为空</span></div>
                    <div class="form_check_ipt">
                        <div class="left check_left">
                            <label><input name="" type="checkbox"> 下次自动登录</label>
                        </div>
                        <div class="right check_right">
                            <a href="#">忘记密码</a>
                        </div>
                    </div>
                    <div class="form_btn">
                        <button type="button" id="loginBtn">登录</button>
                    </div>
                    <div class="form_reg_btn">
                        <span>还没有帐号？</span><a href="/index/user/register">马上注册</a>
                    </div>
                </form>
                <div class="other_login">

                </div>
            </div>
        </div>
    </div>
</div>

{/block}
{block name="script"}
<script type="text/javascript" src="__JS__/common.js" ></script>
<script>
    $(function(){

        $('#loginBtn').on('click',function () {

            let formData = $('#loginForm').serialize();
            $.ajax({
                url:'/index/user/submitLogin',
                data:formData,
                type:'POST',
                success:function (res) {
                    console.log(res)
                    alert('登录成功')
                    localStorage.setItem("username",res.username);
                    localStorage.setItem("user_id",res.id);
                    // sessionStorage.setItem("username",res); //存入 参数： 1.调用的值 2.所要存入的数据
                    //console.log(localStorage.getItem("temp"));//输出

                    location.href = '/'


                   /* $("#loginMain").hide()
                    $("#logged").show()
                    $("#usernameShow").text(res)*/
                },
                error:function (error) {
                    localStorage.removeItem("username")
                    localStorage.removeItem("user_id")
                    alert(error.responseJSON)
                }
            })

        })

    });
</script>
{/block}